<template>
  <div>
    <table class="bs-table" v-if="hasReport">
      <tr class="bs-table_row">
        <th class="bs-table_th" style="width: 200px">报告名称</th>
        <td class="bs-table_td" colspan="3">
          <span>{{reportDetailData.title}}<font style="font-weight: 600;color: black">{{reportDetailData.type}}</font></span>
        </td>
      </tr>
      <tr class="bs-table_row">
        <th class="bs-table_th" style="width: 200px">报告文件</th>
        <div v-for="(item,index) in reportDetailData.files" :key="index" style="margin-left: 5px">
          <preview :attachementId="item.fileId" v-if="item.fileId"></preview>
        </div>
      </tr>
      <tr class="bs-table_row">
        <th class="bs-table_th">相关附件</th>
        <td class="bs-table_td" colspan="3">
          <div v-for="(item,index) in reportDetailData.material_fileId" :key="index">
            <preview :attachementId="item.fileId" v-if="item.fileId"></preview>
          </div>
        </td>
      </tr>
      <tr class="bs-table_row">
        <th class="bs-table_th">起草单位</th>
        <td class="bs-table_td">{{reportDetailData.createUnit}}</td>
        <th class="bs-table_th">起草时间</th>
        <td class="bs-table_td">{{reportDetailData.draftTime}}</td>
      </tr>
      <tr class="bs-table_row" v-if="reportDetailData.havModifyOpinion">
        <th class="bs-table_th">修订调整建议</th>
        <td class="bs-table_td" colspan="3">
          <span style="float:left">{{reportDetailData.modifyOpinion}}</span>
        </td>
      </tr>
      <tr class="bs-table_row">
        <th class="bs-table_th">修订调整建议附件</th>
        <td class="bs-table_td" colspan="3">
          <div v-for="(item,index) in reportDetailData.modifyOpinion_fileId" :key="index">
            <preview :attachementId="item.fileId" v-if="item.fileId"></preview>
          </div>
        </td>
      </tr>
    </table>
    <table class="bs-table" v-if="!hasReport">
      暂无数据
    </table>
  </div>
</template>

<script>
import { getFileTypeFiles, getFileTypeFile } from '@/views/util'
import { getReportDetail } from '@/api/pim/pim'

export default {
  name: 'reprotDetail',
  created() {},

  watch: {
    reportId: {
      immediate: true,
      handler(val) {
        if (val) {
          this.getDetailData_report()
        }
      }
    }
  },
  props: {
    reportId: null
  },
  data() {
    return {
      reportDetailData: {
        reportfile: null,
        type: null,
        title: null,
        createUnit: null,
        createTime: null,
        files: [],
        material_fileId: [],
        modifyOpinion_fileId: [],
        havModifyOpinion: ''
      },
      filesShow: false,
      hasReport:true,
    }
  },
  methods: {
    getDetailData_report() {
      if (this.reportId != null && this.reportId != undefined) {
        this.hasReport = true;
        getReportDetail(this.reportId).then(async response => {
          var records = response.data.data;
          this.$emit('putData', records);
          this.reportDetailData.type = this.reportTypeTransform(
            records.reportType,
            records.year
          );
          this.reportDetailData.title = records.title;
          this.reportDetailData.createUnit = records.createUnit;
          this.reportDetailData.createTime = records.createTime;
          this.reportDetailData.modifyOpinion = records.modifyOpinion;
          this.reportDetailData.havModifyOpinion = records.havModifyOpinion;
          this.reportDetailData.draftTime = records.draftTime;
          let reportfile = await getFileTypeFile(records.reportId);
          this.reportDetailData.reportfile = reportfile[0];

          let files = await getFileTypeFiles(records.fileIds);
          this.reportDetailData.files = files;

          let material_fileId = await getFileTypeFiles(records.material_fileIds);

          this.reportDetailData.material_fileId = material_fileId;
          let modifyOpinion_fileId = await getFileTypeFiles(
            records.modifyOpinion_fileIds
          );
          this.reportDetailData.modifyOpinion_fileId = modifyOpinion_fileId
        })
      }else {
         this.hasReport = false;
      }
    },
    reportTypeTransform(reportType, year) {
      switch (reportType) {
        case '2':
          return '中期评估报告';
          break;
        case '3':
          return '期末总结报告';
          break;
        case '1':
          return year + '年度监测分析报告';
          break
      }
    }
  }
}
</script>

<style scoped>
</style>
